from PyQt4 import QtGui, QtCore
import sys

class TLogin (QtGui.QWidget):

    def __init__(self, parent = None):
        QtGui.QWidget.__init__(self, parent)
        self.label = QtGui.QLabel("enter your password")
        self.pass_edit = QtGui.QLineEdit("")
        self.btnLogin = QtGui.QPushButton("Login")
        self.vbox = QtGui.QVBoxLayout()
        self.vbox.addWidget(self.label)
        self.vbox.addWidget(self.pass_edit)
        self.vbox.addWidget(self.btnLogin)
        self.setLayout(self.vbox)
        self.edited = False
        self.connect(self.pass_edit, QtCore.SIGNAL("editingFinished()"),\
         self.editing_finished)
        self.connect(self.pass_edit, QtCore.SIGNAL("selectionChanged()"), \
        self.clear_edit)
        #self.pass_edit.focusInEvent(self.clear_edit)

    def editing_finished (self):
        print self.edited
        if self.edited == False:
            if self.pass_edit.text() == '':
                self.pass_edit.setText("Enter your password here")
            self.edited = True
        elif self.edited == True and self.pass_edit.text() == '':
            self.pass_edit.setText("Enter your password here:")

    def clear_edit (self):
        print 'textEdited'
        if self.edited == True:
            self.pass_edit.setText("")

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    window = TLogin()
    window.resize(300, 100)
    window.show()
    sys.exit(app.exec_())




